@extends('layouts.admin')

@section('title', config('app.name')."- 内容管理平台")

@section('css')

    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="{{asset('admin/component/pear/css/pear.css')}}" />
    <link rel="stylesheet" href="{{asset('admin/admin/css/other/login.css')}}" />

@endsection

@section('top-js')

@endsection

@section('content')
    <body background="{{asset('admin/admin/images/background.svg')}}" style="background-size: cover;">
    <form class="layui-form" action="{{route('admin.login')}}" method="post">
        @csrf
        <div class="layui-form-item">
            <img class="logo" src="{{asset('admin/admin/images/logo.png')}}" />
            <div class="title">内容管理平台</div>
            <div class="desc">
                智谷内容管理系统
            </div>
        </div>
        <div class="layui-form-item">
            <input type="text" name="name" placeholder="账 户" lay-verify="required" hover class="layui-input"  />
        </div>
        <div class="layui-form-item">
            <input type="password" name="password" placeholder="密 码" lay-verify="required" hover class="layui-input"  />
        </div>
        <div class="layui-form-item">
            <input type="text" name="captcha" id="captcha" placeholder="验证码 : "  hover  lay-verify="required" class="code layui-input layui-input-inline"  />
            <img  id="captchaPic" src="{{captcha_src('mini')}}" onclick='this.src=this.src+"&"+Math.random()' class="codeImage" />
        </div>
        <div class="layui-form-item">
            <input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
        </div>
        <div class="layui-form-item">
            <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
                登 入
            </button>
        </div>
    </form>

    @endsection

    @section('bottom-js')
        <!-- 资 源 引 入 -->
        <script src="{{asset('admin/component/layui/layui.js')}}"></script>
        <script src="{{asset('admin/component/pear/pear.js')}}"></script>
        <script src="{{asset('js/jquery.min.js')}}"></script>
        <script src="{{asset('js/own.js')}}"></script>


        <script>
            layui.use(['form', 'button', 'popup'], function() {
                var form = layui.form;
                var button = layui.button;
                var popup = layui.popup;

                // 登 录 提 交
                form.on('submit(login)', function(formData) {

                    /// 验证
                   // console.log(formData.field)
                    /// 登录
                    sendAjax({
                        'url': "{{ route('admin.login') }}",
                        'data': formData.field,
                        'successCallBack': function(data) {
                            if (data.code == 2000000) {
                                layer.msg(data.message, {
                                    icon: 6,
                                    time: 1000
                                }, function() {
                                    location.href = "{{ route('admin.home') }}";
                                });
                            } else {
                                layer.msg(data.message, {
                                    icon: 5,
                                    time: 3000
                                });
                            }
                        },
                        'errorCallBack': function(jqXHR, textStatus, errorThrown) {

                            // //var errorMessage = "Error: " + jqXHR.responseJSON.message;
                            // layer.msg(errorMessage, {icon: 5, time: 3000});
                            // $("#captchaPic").attr("src",this.+"&"+Math.random())
                            var src = $('#captchaPic')[0].src;
                            $("#captchaPic").attr("src", src + "&" + Math.random())
                            var data = JSON.parse(jqXHR.responseText);
                            layer.msg(data.message, {
                                icon: 5,
                                time: 3000
                            });
                        },
                    });

                      return false;
                });
            })
        </script>
    </body>
@endsection


